// components/person/LoginResign/LoginResign.js
import {countdown} from '../../../utils/countDown.js'
import Notify from '../../../@vant/notify/notify'
import personRequire from '../../../utils/person.js'
const resign = new personRequire()
const smsget = new personRequire()

Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    isCountDown:false,
    timeCountDown:120,
    phone:'',
    sms:'',
    sending:false,
    password:''
  },
  /**
   * 组件的方法列表
   */
  methods: {
    //发送短信验证码
    sendPhone(){//点击事件
      if(!this.data.isCountDown){//当点击后未进行倒计时就开始倒计时
        this.setData({
          isCountDown:true,
          timeCountDown:120
        })
        countdown(this)//倒计时函数
        smsget.sms(this.data.phone).then(data=>{
          if(data === 0){
            this.setData({
              isCountDown:false,
              timeCountDown:0
            })
          }
        })
      }else{
        //正在倒计时时，警报提升
        Notify({ type: 'danger', message: '验证码已发送，请稍后再试' });
      }
    },
    //发送注册登录信息
    Login_Resign(){
      //console.log(this.data.phone,this.data.sms)
      this.setData({
        sending:true
      })
      resign.resign(this.data.phone,this.data.password,this.data.sms).then(()=>{
        this.setData({
          sending:false,
          password:'',
          phone:'',
          sms:''
        })
      })
    },
  },
  attached(){
    
  }
})
